<template>
    <div>
        <div style="text-align: left;">
            处方配药
        </div>
        <br><br>
        <el-table :data="inpatient" style="width: 100%" border stripe >
            <el-table-column prop="pid" label="编号" > </el-table-column>
            <el-table-column prop="pname" label="姓名" > </el-table-column>
            <el-table-column prop="kname" label="科室"> </el-table-column>
        </el-table>
        <el-table :data="inpatient" style="width: 100%" border stripe >
            <el-table-column prop="srid" label="病房编号" > </el-table-column>
            <el-table-column prop="bname" label="病床号" > </el-table-column>
            <el-table-column prop="dname" label="主治医生"> </el-table-column>
        </el-table>
        <el-form ref="form" :model="record" label-width="80px">
                <el-form-item label="药品名称">
                    <el-col :span="8">
                    <el-select v-model="record.medid" placeholder="药品名称">
                        <el-option v-for="medicion in medicionList" :key="medicion.medid" :label="medicion.mdname" :value="medicion.medid">
                        </el-option>
                    </el-select>
                </el-col>
                </el-form-item>
            <el-form-item label="药品数量">
            <el-col :span="8">
                    <el-input v-model="record.mednum" placeholder="药品数量"></el-input>
            </el-col>
        </el-form-item>
        <el-form-item label="使用方法">
            <el-col :span="8">
                <el-input v-model="record.description" placeholder="使用方法"></el-input>
            </el-col>
        </el-form-item>
            <el-col :span="6">
                <el-form-item>
                    <el-button type="primary" @click="updateprescription()">处方修改</el-button>
                </el-form-item>
            </el-col>
            </el-form>
    </div>
</template>

<script>
//导出
export default {
    data() {
        return {
            //患者信息
            inpatient:[],
            record:{},
            //药品集合
            medicionList: [],
        };
    },
    methods: {
        updateprescription(){
            if(this.inpatient[0]==null){
                this.$message("未获得患者信息");
                return;
            }else{

            this.$axios.post("prescription/update",this.record)
                .then((result) => {
                    let vo = result.data;
                    this.$message(vo.message);
                    if (vo.code == 200) {
                        this.list();
                    }
                }).catch((err) => {
                    console.log(err);
                });
            }
        },
        list() {
            this.$axios.get("patient/getOne")
                .then((result) => {
                    let vo = result.data;
                    if (vo.code == 200) {
                        this.inpatient=vo.data;
                  //查询处方
                this.$axios.get("prescription/findPid?pid="+this.inpatient[0].pid)
                .then((result) => {
                    let vo = result.data;
                    if (vo.code == 200) {
                        this.record=vo.data[0];
                    }
                }).catch((err) => {
                    console.log(err);
                });
                    }
                }).catch((err) => {
                    console.log(err);
                });
                //查询所有药品
            this.$axios.get("medicion/findAll1")
                .then((result) => {
                    let vo = result.data;
                    if (vo.code == 200) {
                        this.medicionList = vo.data;
                    }
                }).catch((err) => {
                    console.log(err);
                });
        }
    },
    mounted() {
        this.list();
    },
};
</script>